package com.bwei.like.mynewstop.adapater;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bwei.like.mynewstop.Bean.CityInfo;
import com.bwei.like.mynewstop.R;
import com.bwei.like.mynewstop.base.MyBaseAdapater;
import com.bwei.like.mynewstop.utils.CommonUtils;

import java.util.ArrayList;

/**
 * Created by LiKe on 2016/11/14.
 */
public class CityListItemAdapater extends MyBaseAdapater<CityInfo> {


    public CityListItemAdapater(ArrayList<CityInfo> arrayList, Context context) {
        super(arrayList, context);
    }

    @Override
    public View initView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.city_list_item,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvcityName.setText(arrayList.get(position).getCityName());
        viewHolder.tvcityName.setTextSize(CommonUtils.dip2px(20));
        viewHolder.tvcityName.setPadding(CommonUtils.dip2px(10),CommonUtils.dip2px(10),0,CommonUtils.dip2px(10));
        if (arrayList.get(position).isFlag()){
            viewHolder.tvcitySort.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvcitySort.setVisibility(View.GONE);
        }
        viewHolder.tvcitySort.setTextSize(CommonUtils.dip2px(15));
        viewHolder.tvcitySort.setText(arrayList.get(position).getNameSort());
        return convertView;
    }

    public class ViewHolder {
        public final TextView tvcitySort;
        public final TextView tvcityName;
        public final View root;

        public ViewHolder(View root) {
            tvcitySort = (TextView) root.findViewById(R.id.tv_citySort);
            tvcityName = (TextView) root.findViewById(R.id.tv_cityName);
            this.root = root;
        }
    }
}
